#include <stdio.h>
#include <stdlib.h>

typedef struct{
	int id;
	int score;
}table;

int compare(const void*a,const void*b)
{
	table *s1=(table*)a;
	table *s2=(table*)b;
	return s1->id-s2->id;
}

int main()
{
	int n,m;
	int i,j;
	while(scanf("%d %d",&n,&m)!=EOF)
	{
		table *tablea=(table*)malloc(n*sizeof(table));
		table *tableb=(table*)malloc(m*sizeof(table));
		if(tablea==NULL || tableb==NULL)
		{
			printf("内存分配错误\n");
			return 1;
		}
		for(i=0;i<n;i++)
		{
			scanf("%d %d",&tablea[i].id,&tablea[i].score);
		}
		for(i=0;i<m;i++)
		{
			scanf("%d %d",&tableb[i].id,&tableb[i].score);
		}
		table *tableab=(table*)malloc((n+m)*sizeof(table));
		for(i=0;i<n;i++)
		{
			tableab[i]=tablea[i];
		}
		for(i=0;i<m;i++)
		{
			tableab[n+i]=tableb[i];
		}
		qsort(tableab,n+m,sizeof(table),compare);
		for(j=0;j<n+m;j++)
		{
			printf("%d %d\n",tableab[j].id,tableab[j].score);
		}
		free(tablea);
		free(tableb);
		free(tableab);
		tablea=NULL;
		tableb=NULL;
		tableab=NULL;
	}
	return 0;
}